1 00:00:00,740 --> 00:00:05,540 Welcome back to continue scripting our game and to actually start seeing some of the functionality of 2 00:00:05,540 --> 00:00:06,470 our main GUI. 3 00:00:06,470 --> 00:00:11,390 We should start to script the game handler that is inside of our starter player scripts. 4 00:00:12,270 --> 00:00:17,010 This module script is going to be responsible for listening to when new sections of the game start, 5 00:00:17,010 --> 00:00:20,610 and for animating the player's camera to its respective cut scenes. 6 00:00:20,610 --> 00:00:25,290 So it's going to listen to our game comms event, and it's going to execute code specifically for starting, 7 00:00:25,290 --> 00:00:28,980 like the introduction scene of our game and like the stair scene of our game. 8 00:00:28,980 --> 00:00:32,970 The service will also be responsible for disabling the reset button for our player. 9 00:00:32,970 --> 00:00:34,770 So let's go ahead and open this up. 10 00:00:34,770 --> 00:00:39,720 And inside of here we're only going to need two services replicated storage. 11 00:00:43,000 --> 00:00:46,300 And then we're also going to need the starter guy. 12 00:00:48,410 --> 00:00:51,470 And then we need to create the variable to represent this module script. 13 00:00:51,470 --> 00:00:53,240 So we'll call it game handler. 14 00:00:54,020 --> 00:00:57,770 And we'll make sure to return it at the very end of our script. 15 00:00:59,360 --> 00:01:06,500 Now I'm going to also create a reference to the folder that contains all of the modules on the client. 16 00:01:06,500 --> 00:01:09,980 So in our starter player scripts we have this folder called modules. 17 00:01:09,980 --> 00:01:12,470 And we have a module script in here called Game Scenes. 18 00:01:12,470 --> 00:01:16,880 And this is going to store the code that we need to execute for, you know the different scenes like 19 00:01:16,880 --> 00:01:19,460 the intro scene, the stairs scene and stuff like that. 20 00:01:19,790 --> 00:01:27,950 So we can reference that section in our code by either grabbing the local player going into their player 21 00:01:27,950 --> 00:01:30,590 scripts folder and getting the modules folder that way. 22 00:01:30,590 --> 00:01:36,020 Or we can also get the modules folder by simply referencing the script itself, getting the parent of 23 00:01:36,020 --> 00:01:42,200 the script which would be the handlers folder, and then getting the parent of this folder, which would 24 00:01:42,200 --> 00:01:42,800 be the client. 25 00:01:42,800 --> 00:01:46,040 And then from that point we can grab our modules folder. 26 00:01:46,340 --> 00:01:51,020 After this point, we're going to make a reference to our game comms event which is in replicated storage, 27 00:01:51,020 --> 00:01:54,470 dot events, dot remotes, dot game communication. 28 00:01:54,470 --> 00:01:57,710 And then we're also going to get the game comms enum. 29 00:01:57,710 --> 00:02:03,740 So we'll require this from updated storage dot modules dot enums dot game communication enum. 30 00:02:04,340 --> 00:02:08,720 And then we're going to go ahead and also require our game scenes module script. 31 00:02:08,720 --> 00:02:11,720 So inside of here I'm just going to create a quick table. 32 00:02:11,720 --> 00:02:13,550 We'll just call it game scenes. 33 00:02:13,550 --> 00:02:16,250 And we'll make sure to return it at the end here as well. 34 00:02:17,460 --> 00:02:19,590 And then in here we'll just make a reference to it. 35 00:02:19,590 --> 00:02:23,760 We'll just call it scenes and we'll require it from our modules folder. 36 00:02:23,760 --> 00:02:25,350 Dot game scenes. 37 00:02:25,800 --> 00:02:30,150 Now inside of here we're going to need a function for initializing the game handler. 38 00:02:31,400 --> 00:02:34,400 And we're also going to need a function for starting our game handler. 39 00:02:36,230 --> 00:02:41,960 So inside of our initialize section, all we need to do is listen to our games comms event on client 40 00:02:41,960 --> 00:02:45,020 event, and we can go ahead and connect a private function for this. 41 00:02:45,020 --> 00:02:46,880 So we can create a private function in here. 42 00:02:46,880 --> 00:02:50,810 And we'll call it on game comms event. 43 00:02:50,810 --> 00:02:53,660 We get passed an action and arguments for that action. 44 00:02:53,660 --> 00:02:56,990 And we'll connect to this function to our game comms event. 45 00:02:57,780 --> 00:03:02,490 And inside of here, all we need to check is if the action is equal to the game. 46 00:03:02,490 --> 00:03:07,230 Comms enum dot two client dot start intro scene. 47 00:03:07,230 --> 00:03:12,360 If we're going to start the intro scene, then we're going to execute a function within our scenes module 48 00:03:12,360 --> 00:03:13,050 script. 49 00:03:13,800 --> 00:03:20,190 Otherwise, if the action is let's say game comms enum dot two client dot start stair scene, then we're 50 00:03:20,190 --> 00:03:22,140 going to do that other scene as well. 51 00:03:22,140 --> 00:03:25,830 And then inside of the start function for our game handler, all we're going to do is reference our 52 00:03:25,830 --> 00:03:32,820 started UI and use the set core function to disable the reset button callback. 53 00:03:32,820 --> 00:03:39,150 That way our players are unable to use the reset button, and we do not have to use a p call on this 54 00:03:39,150 --> 00:03:43,680 function, because this module script is only going to run after the game has loaded. 55 00:03:43,680 --> 00:03:46,740 So all of our core scripts should be available and ready to go. 56 00:03:46,740 --> 00:03:49,230 And we don't have to wrap this function here in a P call. 57 00:03:49,840 --> 00:03:55,840 So when we are given, for example, a command or action to start the intro scene, we could reference 58 00:03:55,840 --> 00:04:02,230 our scenes module script and we could have a function in there like start intro scene and pass the arguments 59 00:04:02,230 --> 00:04:05,350 along with it to, you know, start the intro scene. 60 00:04:05,350 --> 00:04:08,620 And then we could also do the same thing for the star scene. 61 00:04:08,620 --> 00:04:11,170 We could just name this function start Star scene. 62 00:04:11,860 --> 00:04:14,920 So let's go ahead and go into our game scenes module script. 63 00:04:14,920 --> 00:04:18,040 And inside of here we're going to need a few services. 64 00:04:18,040 --> 00:04:20,500 We're of course going to need replicated storage. 65 00:04:23,950 --> 00:04:26,680 We're going to need the tween service. 66 00:04:29,820 --> 00:04:32,100 We are going to need the run service. 67 00:04:34,380 --> 00:04:36,870 We will need the player service. 68 00:04:38,170 --> 00:04:41,350 And I believe that's all of the services we'll need in here for now. 69 00:04:41,590 --> 00:04:43,690 So some variables we're going to have to make. 70 00:04:43,690 --> 00:04:45,910 First off is a reference to the local player. 71 00:04:45,910 --> 00:04:47,980 So player's dot local player. 72 00:04:47,980 --> 00:04:53,890 We're going to make a reference to a different uh bindable event in replicated storage. 73 00:04:53,890 --> 00:04:56,650 And this is called uh update Guy. 74 00:04:56,650 --> 00:05:00,250 But it's a bindable event so we can call it Guy bind event. 75 00:05:00,280 --> 00:05:04,690 It's in replicated storage, dot events, dot Bindesboll's dot update guy. 76 00:05:04,690 --> 00:05:12,880 And we're going to use this Bindable event to communicate to our, uh, main guy handler to, uh, do 77 00:05:12,910 --> 00:05:13,900 different actions. 78 00:05:13,900 --> 00:05:20,770 For example, uh, doing something like the intro message to display on the screen when the game starts. 79 00:05:21,750 --> 00:05:27,360 And since we're going to be using this event, we should also grab our GUI actions enum from upper storage 80 00:05:27,360 --> 00:05:27,930 as well. 81 00:05:27,930 --> 00:05:31,620 So module dot enums dot gui actions enum. 82 00:05:32,320 --> 00:05:36,010 Then we're going to make a reference to the current camera in the workspace. 83 00:05:36,010 --> 00:05:37,810 So workspace dot current camera. 84 00:05:37,930 --> 00:05:42,520 And then we're also going to have to make a reference to our filtering folder in the workspace. 85 00:05:42,520 --> 00:05:47,260 Because there are some invisible parts in there that we need to tween something to. 86 00:05:47,260 --> 00:05:49,000 And you'll see what that is in a moment. 87 00:05:49,600 --> 00:05:52,240 And I'm also going to be creating a new random data type. 88 00:05:52,810 --> 00:05:58,930 Now, the two functions we're going to need in here for now is one to start our intro scene. 89 00:05:58,930 --> 00:06:01,660 And if you remember, we get past arguments to this function. 90 00:06:01,660 --> 00:06:05,980 And we're also going to need a function to start the stair scene. 91 00:06:08,460 --> 00:06:10,830 And we get past arguments to that as well. 92 00:06:11,610 --> 00:06:16,920 Now when this module script gets told to start the introduction scene, what we need to first do is 93 00:06:16,920 --> 00:06:25,410 reference our GUI Bindable event and fire to our main GUI handler that we wish to do an action of the 94 00:06:25,410 --> 00:06:26,070 intro message. 95 00:06:26,070 --> 00:06:28,560 So we want to start up our intro message. 96 00:06:28,560 --> 00:06:34,290 So that means if we go back to our main GUI handler, we need to create a section for handling that 97 00:06:34,290 --> 00:06:35,490 Bindable event. 98 00:06:35,490 --> 00:06:38,880 So inside of our variable section we can make a reference to it real quick. 99 00:06:38,880 --> 00:06:46,290 We'll just call it update GUI bind event and that's in replicated storage dot events dot binding bulls 100 00:06:46,290 --> 00:06:47,910 dot update GUI. 101 00:06:48,670 --> 00:06:54,610 And then what we could do is we could go ahead and scroll down to our initialize function. 102 00:06:54,610 --> 00:06:55,300 Here we are. 103 00:06:55,300 --> 00:06:58,720 And we can go ahead and add a section to listening to this event. 104 00:06:58,720 --> 00:07:04,870 So we can refer to our update Guy Bindable event and listen for when it gets fired. 105 00:07:05,740 --> 00:07:09,850 We'll get the action for this event and argument supplied to the action. 106 00:07:09,850 --> 00:07:15,130 And the only action we are going to listen for in here is our intro message action. 107 00:07:15,130 --> 00:07:22,360 So if the action is equal to GUI actions enum dot intro message, then all we're going to do is we're 108 00:07:22,360 --> 00:07:28,330 going to first make sure inside of our message frame that the text label in there has no current text. 109 00:07:28,330 --> 00:07:30,010 So we're going to set it to be blank. 110 00:07:30,310 --> 00:07:34,210 And then we're going to set the message frame dot visibility equal to true. 111 00:07:34,770 --> 00:07:41,910 And then we're going to use our display intro message function and pass inside of the messages table 112 00:07:41,910 --> 00:07:43,110 our action. 113 00:07:43,110 --> 00:07:48,750 Because remember inside of the messages table for our particular intro message action, we have three 114 00:07:48,750 --> 00:07:51,660 different messages we need to display onto the screen. 115 00:07:52,180 --> 00:07:55,270 We also need to pass a delay between the messages. 116 00:07:55,300 --> 00:08:00,550 Now of course we could hard code it in here, or we could give our game scenes module script control 117 00:08:00,550 --> 00:08:05,890 over how many seconds we want to wait between each of the messages, so we could pass a table here and 118 00:08:05,890 --> 00:08:09,640 inside create a key for something like delay. 119 00:08:10,400 --> 00:08:14,120 Between messages and we could set it to something like four seconds. 120 00:08:14,120 --> 00:08:18,500 And since we're going to be getting this key passed to our ARGs table, we can just go ahead and pass 121 00:08:18,500 --> 00:08:23,960 args dot delay between messages. 122 00:08:24,290 --> 00:08:30,050 So now when we go ahead and call this function it's going to display our message frame on the screen. 123 00:08:30,050 --> 00:08:35,480 And it's going to set the text in there to each of the different texts inside of the table that was 124 00:08:35,480 --> 00:08:39,830 passed to the function plays the sound, and then eventually, after it passes through all the messages, 125 00:08:39,830 --> 00:08:41,570 it fades out our message frame. 126 00:08:42,780 --> 00:08:43,200 All right. 127 00:08:43,200 --> 00:08:48,270 So then the next thing that we could do inside of our start intro stream function is that we want to 128 00:08:48,270 --> 00:08:54,630 refer to our current camera, and we want to set the camera type equal to the enum dot camera TypeScript 129 00:08:54,630 --> 00:08:55,230 label. 130 00:08:55,230 --> 00:09:00,060 And then we want to set the current camera's dot frame equal to a new position. 131 00:09:00,060 --> 00:09:04,260 And that new position is going to be inside of our bus. 132 00:09:04,260 --> 00:09:09,390 So if we go on the map here and looks like I went the wrong direction, let me let me try to find the 133 00:09:09,390 --> 00:09:10,290 bus somewhere. 134 00:09:10,320 --> 00:09:12,570 Our bus should be around here somewhere. 135 00:09:13,500 --> 00:09:14,250 Oh, I saw it. 136 00:09:14,250 --> 00:09:15,090 There it is. 137 00:09:15,420 --> 00:09:18,900 So we need to set our camera c frame to this invisible part. 138 00:09:18,900 --> 00:09:24,180 And then we need to tween this bus along the road and have our camera continually update and follow 139 00:09:24,180 --> 00:09:25,620 the position of this part. 140 00:09:26,150 --> 00:09:29,630 So inside of here we could also create a reference to the bus itself. 141 00:09:29,630 --> 00:09:31,100 We'll create a variable in this function. 142 00:09:31,100 --> 00:09:32,390 We'll just call it bus. 143 00:09:32,390 --> 00:09:37,460 And that's going to be equal to the workspace dot outdoor folder dot bus. 144 00:09:38,000 --> 00:09:39,920 Then we can reference our bus. 145 00:09:39,920 --> 00:09:44,330 And inside of the bus there's our invisible part, which is called the camera anchor. 146 00:09:44,330 --> 00:09:49,310 And we're going to set the key frame of our camera equal to the key frame of our bus. 147 00:09:49,640 --> 00:09:56,090 Afterwards, we're going to have to wait for a little bit of time before we start tweening our bus along 148 00:09:56,090 --> 00:09:57,980 the route that we want it to go. 149 00:09:58,010 --> 00:10:05,660 So because we are delaying between each message for four seconds and we have a total of three messages, 150 00:10:05,660 --> 00:10:09,800 we're going to have to wait at least 12 seconds before we actually start moving the bus. 151 00:10:09,800 --> 00:10:13,580 Otherwise, the players aren't going to see it because their screen's covered by a guy. 152 00:10:13,580 --> 00:10:18,140 So we're just going to put a wait statement in here of 12 seconds, and then after that, 12 seconds 153 00:10:18,140 --> 00:10:22,100 are up, we can go ahead and run the tweens for moving the bus. 154 00:10:22,100 --> 00:10:26,780 So I'm going to create the first tween for the bus, which will move it to the first position. 155 00:10:26,780 --> 00:10:30,980 So tween service we're going to create on our bus dot primary part. 156 00:10:30,980 --> 00:10:34,700 And this is the part that everything in our bus is welded to. 157 00:10:35,270 --> 00:10:39,260 And we could do tween info dot new and we can make the bus drive. 158 00:10:39,260 --> 00:10:46,070 I found that 11 seconds works pretty good, and we can put even a custom enum dot easing style in here 159 00:10:46,070 --> 00:10:52,790 of quad, and this helps to imitate the bus speeding up and then slowing down instead of moving linearly. 160 00:10:53,240 --> 00:10:58,130 And now we want to update the keyframe of our buses primary part equal to. 161 00:10:58,310 --> 00:11:00,320 Inside of the filtering folder. 162 00:11:00,320 --> 00:11:05,870 There is another folder called Bus Goals, and there's two different parts in there that represent the 163 00:11:05,870 --> 00:11:08,360 different keyframes we need to move our bus to. 164 00:11:08,360 --> 00:11:10,550 And this would be bus goal number one. 165 00:11:10,550 --> 00:11:12,890 And we're going to get the keyframe of this part. 166 00:11:13,440 --> 00:11:16,230 And then we're basically just going to copy this again. 167 00:11:16,800 --> 00:11:19,440 But instead we're going to make a second tween. 168 00:11:19,440 --> 00:11:21,120 We'll call it tween number two. 169 00:11:21,120 --> 00:11:26,010 And this time we want to tween our bus two, bus goal number two. 170 00:11:26,040 --> 00:11:29,730 So if we go ahead and look on the map here and let me go to the filtering folder. 171 00:11:29,730 --> 00:11:30,540 Bus goals. 172 00:11:30,540 --> 00:11:32,580 We have bus goal one and bus goal two. 173 00:11:33,030 --> 00:11:38,280 So if we go down here, our first bus goal stops at the entrance of the Krusty Krab. 174 00:11:38,280 --> 00:11:41,730 And then the second bus goal goes all the way to the end of the road. 175 00:11:41,730 --> 00:11:45,990 And at this point, when the bus reaches the second goal, we can basically just destroy it off the 176 00:11:45,990 --> 00:11:47,970 map because we don't need to use it anymore. 177 00:11:48,600 --> 00:11:53,400 So that means we can go ahead and refer to our first tween and then just play it. 178 00:11:53,460 --> 00:12:01,800 Now the problem with this is that our camera is not welded or attached to that camera anchor part in 179 00:12:01,800 --> 00:12:02,430 our bus. 180 00:12:02,460 --> 00:12:07,410 We aren't able to weld our camera to anything, so that means every single frame we're going to have 181 00:12:07,410 --> 00:12:12,930 to update the position of our camera to the position of our camera anchor part. 182 00:12:12,960 --> 00:12:19,050 So that means we're going to have to use our run service and bind a function to the render step event. 183 00:12:19,050 --> 00:12:23,580 So inside of the run service we're going to use the function bind to render step. 184 00:12:23,580 --> 00:12:24,840 We can give it whatever name. 185 00:12:24,840 --> 00:12:27,900 But we're going to call this camera anchor in. 186 00:12:27,900 --> 00:12:34,470 The priority for this is going to be equal to the enum dot render priority dot camera plus one. 187 00:12:34,470 --> 00:12:40,500 This is important that you do plus one because we're going to be moving the camera after the camera 188 00:12:40,500 --> 00:12:41,670 has been updated. 189 00:12:41,670 --> 00:12:46,350 So that way it doesn't look weird or we're not getting any jittering problems when we're trying to move 190 00:12:46,350 --> 00:12:51,600 the camera, because if we made the render priority before the camera, then we're going to be moving 191 00:12:51,600 --> 00:12:54,630 the see frame of our camera to a parts position. 192 00:12:54,630 --> 00:12:59,250 That may not be correct, so we're going to do it after the camera has been updated. 193 00:12:59,370 --> 00:13:03,750 And then we can go ahead and pass the function we wish to bind to render stepped. 194 00:13:04,170 --> 00:13:08,550 And what we're going to do in here is we're just going to refer to our current camera, and we're going 195 00:13:08,550 --> 00:13:13,320 to set the key frame equal to the camera anchor key frame. 196 00:13:13,440 --> 00:13:20,010 However, if we just did bus dot camera anchor dot key frame and we just set our camera key frame to 197 00:13:20,010 --> 00:13:25,650 the buses key frame every single time, then it's going to look all kind of weird and jittery. 198 00:13:25,650 --> 00:13:27,330 And I'm going to show you what I mean. 199 00:13:28,130 --> 00:13:35,450 So remember inside of our game service, when the game starts, we're going to tell all of the clients 200 00:13:35,450 --> 00:13:37,610 to start the intro scene. 201 00:13:38,730 --> 00:13:41,760 And actually we don't need to pass the bus object itself. 202 00:13:41,760 --> 00:13:45,720 I mean, you can do this from the server, but the more I think about it, I think it's just better 203 00:13:45,720 --> 00:13:51,210 if we just pass the action instead and have the clients refer to the bus on their end. 204 00:13:51,210 --> 00:13:54,480 That way we don't have to pass any extra unnecessary information. 205 00:13:54,480 --> 00:13:57,450 But basically we're going to tell all the players to start the intro scene. 206 00:13:57,450 --> 00:14:00,810 And that's basically what's going to call this function right here. 207 00:14:00,810 --> 00:14:03,510 So that means if we go and play test our game. 208 00:14:04,750 --> 00:14:06,610 We should see that. 209 00:14:07,120 --> 00:14:09,340 Okay, we're getting our intro messages. 210 00:14:10,990 --> 00:14:13,900 And the sound is playing for them as well, which is nice. 211 00:14:19,540 --> 00:14:21,190 And now we have attached to the camera. 212 00:14:21,190 --> 00:14:27,190 But it looks like we did get an error attempt to perform arithmetic add on enum item and number I. 213 00:14:27,190 --> 00:14:34,300 And that's because we accidentally forgot to refer to the value of this render priority. 214 00:14:34,300 --> 00:14:40,390 So inside of the camera's render priority, we need to refer to the value stored in this enum instead 215 00:14:40,390 --> 00:14:41,500 of the enum itself. 216 00:14:41,500 --> 00:14:44,650 So that way we're getting the number and then adding one to it. 217 00:14:44,800 --> 00:14:46,570 So that's a quick error we just fixed. 218 00:14:46,570 --> 00:14:48,100 Let's go ahead and try this out again. 219 00:14:49,860 --> 00:14:50,550 All right. 220 00:14:50,550 --> 00:14:54,240 And now, as you see, our camera is following our bus. 221 00:14:54,240 --> 00:15:00,660 But the problem with this is that our bus looks like it's moving a little bit with some jitter to it, 222 00:15:00,810 --> 00:15:03,330 and that jitter can be a little unpleasant. 223 00:15:03,330 --> 00:15:05,400 So the way we can fix this jitter. 224 00:15:06,090 --> 00:15:11,040 Is that inside of our game seeing function, when we're setting the camera, see frame equal to the 225 00:15:11,040 --> 00:15:17,370 see frame of our camera anchor, what we can do instead is we can refer to the current camera, see 226 00:15:17,370 --> 00:15:24,030 frame, and we can use the lerp function or the linear interpolation function to move it to the bus 227 00:15:24,030 --> 00:15:26,160 dot camera anchor dot see frame. 228 00:15:26,160 --> 00:15:32,340 But we're going to pass an alpha value dependent on the delta time that gets passed to our lambda function. 229 00:15:32,340 --> 00:15:38,220 And again, this delta time is going to tell us how much time was passed or what's the delay between 230 00:15:38,220 --> 00:15:39,060 frames. 231 00:15:39,060 --> 00:15:43,500 And using this delay you could actually also calculate the frame rate of your game. 232 00:15:43,500 --> 00:15:48,060 So if you divided one by the delta time it's going to give you the frame rate. 233 00:15:48,060 --> 00:15:54,180 So if we were running at 60 frames per second, that means the delta time or the time between frames 234 00:15:54,180 --> 00:15:56,970 is about 0.016 seconds. 235 00:15:57,510 --> 00:16:01,830 So for the alpha value, what we're going to do is we're going to pass our delta time. 236 00:16:01,830 --> 00:16:06,060 And then we're going to multiply this delta time by a particular number. 237 00:16:06,060 --> 00:16:10,530 And most people that I've seen in scripting call this number a smoothing value. 238 00:16:10,530 --> 00:16:12,360 So we can create a variable outside of here. 239 00:16:12,360 --> 00:16:13,950 And we can call it smoothing. 240 00:16:13,950 --> 00:16:20,490 And we can set it to a number like 60 to represent the default amount of frames that Roblox runs in, 241 00:16:20,490 --> 00:16:22,230 which is 60 frames per second. 242 00:16:22,590 --> 00:16:28,080 So this will help our camera linearly interpolate to the bus's C frame. 243 00:16:28,080 --> 00:16:33,840 But each time we're not moving all the way to this new C frame because we're multiplying it by the delta 244 00:16:33,840 --> 00:16:35,670 time and the smoothing value. 245 00:16:35,670 --> 00:16:42,030 So in every instance when our delta time changes, either due to increases in frame rate or lag spikes, 246 00:16:42,030 --> 00:16:49,080 that causes drops in frame rate, we should reduce the problem of where the camera movement on the bus 247 00:16:49,080 --> 00:16:52,920 looks jittery, and to confirm this we can go ahead and test this out again. 248 00:16:55,310 --> 00:16:55,580 All right. 249 00:16:55,580 --> 00:17:01,160 As you can see, our bus is no longer jittering and our camera movement has improved considerably. 250 00:17:01,160 --> 00:17:03,800 As you can tell, it's no longer jittery. 251 00:17:03,800 --> 00:17:07,250 The bus isn't moving weirdly, and our camera isn't jittering around either. 252 00:17:07,250 --> 00:17:13,940 We now have a nice smooth tween basically of our camera all the way along this bus ride. 253 00:17:14,780 --> 00:17:20,510 Now you can go ahead and mess with the smoothing value all you like, but I found that a value of 60 254 00:17:20,510 --> 00:17:22,850 works pretty well in most cases. 255 00:17:23,360 --> 00:17:29,090 Now, to further add to the ambience of our game, we also want to make sure that the bus sounds like 256 00:17:29,090 --> 00:17:29,630 it's running. 257 00:17:29,630 --> 00:17:32,930 So we want to enable like an engine sound in our bus. 258 00:17:32,930 --> 00:17:41,150 And thankfully inside of our bus and inside of the body of the bus, there is a sound called engine 259 00:17:41,150 --> 00:17:44,210 and this is going to imitate when the bus is driving. 260 00:17:44,210 --> 00:17:49,670 So if we actually go into the workspace and we go to our bus and we go to the body of the bus, here's 261 00:17:49,670 --> 00:17:51,590 our engine sound and I'll just play it here. 262 00:17:52,510 --> 00:17:56,350 This sound just helps to make it sound like, you know, our bus is actually driving. 263 00:17:56,950 --> 00:18:00,850 And then what we're going to do is we're going to refer to our first tween, and we're going to wait 264 00:18:00,850 --> 00:18:02,020 for it to complete. 265 00:18:02,510 --> 00:18:07,760 Because after it completes, then what we could do is we could unbind this function, our camera anchor 266 00:18:07,760 --> 00:18:13,190 function, from the render step, because we don't need the camera to continually follow the camera 267 00:18:13,190 --> 00:18:14,480 anchor part in our bus. 268 00:18:14,480 --> 00:18:20,060 So inside the run service there's a function unbind from render step, and all we need to pass is the 269 00:18:20,060 --> 00:18:23,660 name of this particular function, which was camera anchor. 270 00:18:24,110 --> 00:18:30,380 And then what we're going to do is we're going to make it sound like the bus is now idling, because 271 00:18:30,380 --> 00:18:32,660 it has stopped to drop all of our players off. 272 00:18:32,660 --> 00:18:40,220 So what we're going to do is we're going to create a new tween using our tween service on our bus dot 273 00:18:40,220 --> 00:18:42,020 body dot engine sound. 274 00:18:42,560 --> 00:18:44,900 We're going to use tween info dot new. 275 00:18:44,930 --> 00:18:47,810 We can tween it for like something like 0.8 seconds. 276 00:18:47,810 --> 00:18:52,160 And the thing we want to change inside of the sound instance is the playback speed. 277 00:18:52,910 --> 00:18:58,610 And this will help to make the engine sound like it's idling down or not spinning as fast anymore. 278 00:18:58,640 --> 00:19:03,380 So inside of each sound instance we have a playback speed property. 279 00:19:03,380 --> 00:19:05,450 So normally it sounds like this. 280 00:19:05,450 --> 00:19:10,490 But if I were to decrease this number to something like 0.6, as you can see now, it sounds like our 281 00:19:10,490 --> 00:19:12,530 bus is idling instead of driving. 282 00:19:16,090 --> 00:19:17,950 So we can go ahead and play this tween. 283 00:19:18,720 --> 00:19:26,190 And then inside of the bus dot body, there's another sound called door and we're going to play the 284 00:19:26,190 --> 00:19:29,460 sound to make it, you know, sound like the door of the bus is opening. 285 00:19:29,460 --> 00:19:30,960 So I'll play it real quick for you. 286 00:19:33,540 --> 00:19:34,290 Okay, there we go. 287 00:19:34,290 --> 00:19:41,130 The door of our bus open, and once the door of our bus opens, um, we're going to actually just wait 288 00:19:41,130 --> 00:19:42,360 for two seconds. 289 00:19:43,090 --> 00:19:46,600 And then we're going to get our local player. 290 00:19:46,600 --> 00:19:49,870 We're going to refer to the local player's character. 291 00:19:49,900 --> 00:19:52,390 Get our humanoid root part. 292 00:19:53,030 --> 00:19:57,500 And we're going to set the keyframe of our humanoid root part equal to a part. 293 00:19:57,530 --> 00:19:59,120 Keyframe in the workspace. 294 00:19:59,120 --> 00:20:05,150 So we have another part inside of our filtering folder, and it's inside of our teleport parts folder, 295 00:20:05,150 --> 00:20:06,770 and it's called Bus Stop. 296 00:20:06,860 --> 00:20:11,480 So this is the position that we want the players to move their position to. 297 00:20:11,480 --> 00:20:16,760 And then what we're going to do is we're going to basically just randomly position all of the players, 298 00:20:16,970 --> 00:20:19,460 uh, around here on this platform. 299 00:20:19,550 --> 00:20:22,700 So that way they don't all pile up at the same spot. 300 00:20:22,700 --> 00:20:28,310 So basically what we're going to do is we're going to refer to the filtering folder inside of there. 301 00:20:28,310 --> 00:20:33,620 We're going to get the teleport parts folder and then refer to the bus stop part and get that keyframe. 302 00:20:33,620 --> 00:20:37,520 And then we're going to add an offset to the keyframe by using vector three. 303 00:20:37,520 --> 00:20:43,160 That way we are offsetting in the global axes of our game, and we're just going to create a new vector 304 00:20:43,160 --> 00:20:49,790 three, and we're going to use our RNG next integer to move the player anywhere between, let's say 305 00:20:49,790 --> 00:20:52,910 negative four and four studs on the x axis. 306 00:20:52,910 --> 00:20:59,060 So that means when our players spawn here, they will randomly move anywhere from over here or over 307 00:20:59,060 --> 00:20:59,600 here. 308 00:20:59,600 --> 00:21:03,140 Or we could also move them positively over here or over here. 309 00:21:03,260 --> 00:21:10,190 And actually we could also reposition this part slightly to be more in the center of our, uh, platform 310 00:21:10,190 --> 00:21:11,510 here or this walkway. 311 00:21:11,510 --> 00:21:16,010 So we will basically set the player keyframe to here, and then we're just going to offset it. 312 00:21:16,010 --> 00:21:22,580 So each player will spawn randomly either on this side maybe over here, over here, back here or whatever. 313 00:21:22,580 --> 00:21:26,870 We just don't want them all to teleport themselves to the exact same position. 314 00:21:27,860 --> 00:21:29,180 So we'll move them randomly. 315 00:21:29,180 --> 00:21:32,630 Negative four to positive four studs on the x axis. 316 00:21:32,630 --> 00:21:34,940 We do not have to worry about the y axis. 317 00:21:34,940 --> 00:21:37,790 And then we're going to do the same thing on the z axis. 318 00:21:37,790 --> 00:21:40,010 We could do -4 to 4. 319 00:21:40,310 --> 00:21:45,680 And then after that, since the player's camera is still going to be attached to our camera anchor part, 320 00:21:45,680 --> 00:21:51,320 or basically we still have it in the scriptable mode and the player's camera is going to be stuck sitting 321 00:21:51,320 --> 00:21:51,560 there. 322 00:21:51,560 --> 00:21:55,130 We need to tween the player's camera back to their character. 323 00:21:55,520 --> 00:21:58,370 So what we could do is we could create a tween on the camera. 324 00:21:58,370 --> 00:21:59,810 I'll call it cam tween. 325 00:21:59,810 --> 00:22:03,410 So tween service create on our current camera. 326 00:22:03,590 --> 00:22:10,490 We could do a tween info of like one second and we could do a different enemies style like sine just 327 00:22:10,490 --> 00:22:12,110 to make it a little more fancy. 328 00:22:12,920 --> 00:22:16,850 And we're going to set the keyframe of our camera. 329 00:22:17,920 --> 00:22:21,220 Equal to the local player dot character. 330 00:22:21,770 --> 00:22:27,050 And we could get something like their head and get the C frame of the player's head. 331 00:22:27,050 --> 00:22:29,900 So basically we're just moving the camera to the player's head. 332 00:22:30,970 --> 00:22:33,970 And then we're going to wait for this camera twin to finish. 333 00:22:33,970 --> 00:22:35,140 So Dot completed. 334 00:22:35,140 --> 00:22:35,980 Wait. 335 00:22:37,480 --> 00:22:44,140 And then we're basically just going to reset the current camera's camera type equal to enum dot camera 336 00:22:44,140 --> 00:22:49,840 type dot custom, which will allow the default course scripts for controlling the camera to take back 337 00:22:49,840 --> 00:22:50,650 over. 338 00:22:50,650 --> 00:22:54,430 So if we go ahead and test what we have gotten done so far. 339 00:22:56,560 --> 00:23:01,810 So as you can see, our bus is driving, we're going down along the road and eventually we should slow 340 00:23:01,810 --> 00:23:02,410 down here. 341 00:23:02,410 --> 00:23:06,130 And as you can see, our bus is slowing down until we reach our bus stop point. 342 00:23:07,940 --> 00:23:08,300 There we go. 343 00:23:08,300 --> 00:23:09,230 Our bus idles down. 344 00:23:09,230 --> 00:23:10,370 The door opens. 345 00:23:13,100 --> 00:23:17,840 And any second now our camera should snap back to our player. 346 00:23:18,950 --> 00:23:21,440 But it doesn't look like that's happening. 347 00:23:21,440 --> 00:23:26,330 Probably because we forgot to play our camera team. 348 00:23:26,360 --> 00:23:27,830 Yeah, that's the issue. 349 00:23:27,890 --> 00:23:34,340 So, uh, before we yield, we actually have to make sure that we play the camera tween first. 350 00:23:34,340 --> 00:23:34,820 Okay. 351 00:23:34,820 --> 00:23:35,240 My bad. 352 00:23:35,240 --> 00:23:36,800 Let's go ahead and try this out again. 353 00:23:38,290 --> 00:23:45,250 Our bus is driving down the road, it slows down here and then our camera should tween back to our player. 354 00:23:45,250 --> 00:23:46,240 There we go. 355 00:23:46,540 --> 00:23:50,230 And now we have spawned here and we're ready to enter into our restaurant. 356 00:23:50,470 --> 00:23:55,900 The next things we need to do is we need to restrict our camera to be first person only, and we need 357 00:23:55,900 --> 00:24:00,730 to continue twinning the bus to its opposite position on the other end of this road. 358 00:24:00,730 --> 00:24:02,620 So let's go ahead and do that as well. 359 00:24:03,540 --> 00:24:08,070 So after our camera twin completes, what we're going to do is we're going to refer to our local player. 360 00:24:08,250 --> 00:24:14,430 We're going to get the camera mode property, and we're going to set this to the enum dot camera mode, 361 00:24:14,910 --> 00:24:16,860 dot lock first person. 362 00:24:17,480 --> 00:24:25,520 And then we can set the local player camera max zoom distance equal to 0.5, which basically stops them 363 00:24:25,520 --> 00:24:29,540 from zooming out and they will forever be stuck in first person mode. 364 00:24:29,570 --> 00:24:35,960 Then we can set the camera type back to custom, and then after that's done, we can do something like 365 00:24:35,960 --> 00:24:40,850 wait another two seconds so the bus doesn't immediately leave, and then after those two seconds we're 366 00:24:40,850 --> 00:24:42,620 going to play our second tween. 367 00:24:43,550 --> 00:24:49,280 So our bus drives away from us, and that means we're going to have to override our sound tween that 368 00:24:49,280 --> 00:24:50,840 we created earlier. 369 00:24:51,510 --> 00:24:53,970 So we're going to have to copy this here. 370 00:24:53,970 --> 00:24:57,270 And we're going to create a new tween again on the engine sound. 371 00:24:57,270 --> 00:25:01,350 And instead we're going to set the playback speed back to one. 372 00:25:01,470 --> 00:25:04,980 And then we're going to wait for tween number two to complete. 373 00:25:05,130 --> 00:25:11,640 And then once it has been completed then we're going to basically just destroy our bus because we don't 374 00:25:11,640 --> 00:25:12,990 need it any longer. 375 00:25:12,990 --> 00:25:16,170 And I believe that's our entire start intro scene complete. 376 00:25:16,170 --> 00:25:18,810 So let's go ahead and see what we've got done so far. 377 00:25:22,260 --> 00:25:22,800 Here we are. 378 00:25:22,800 --> 00:25:24,090 We got 11:00. 379 00:25:24,090 --> 00:25:27,900 We should get our next message on a bus to the Krusty Krab for your first shift. 380 00:25:27,930 --> 00:25:32,880 We'll get our third message, and then we should get our camera set to the bus. 381 00:25:32,910 --> 00:25:33,630 Here we go. 382 00:25:33,630 --> 00:25:34,830 We're driving down the road. 383 00:25:34,830 --> 00:25:36,270 We're going to the Krusty Krab. 384 00:25:36,480 --> 00:25:39,090 We also see our objectives shown up here as well. 385 00:25:40,590 --> 00:25:44,220 So we got to earn $500 to pay for rent, and we got to enter the Krusty Krab. 386 00:25:45,670 --> 00:25:47,710 We get our camera tween back to our player. 387 00:25:47,710 --> 00:25:49,900 And as you can see, we're stuck in first person now. 388 00:25:50,080 --> 00:25:54,100 Our bus drives away and eventually it should get destroyed down there. 389 00:25:54,100 --> 00:25:54,970 Perfect. 390 00:25:55,150 --> 00:25:59,650 So we've got all of the introduction stuff done for our game. 391 00:25:59,650 --> 00:26:04,690 I think the next thing we need to do for our game is actually script, the module script that's going 392 00:26:04,690 --> 00:26:09,820 to handle opening and closing all of the doors in our game, because right now we are unfortunately 393 00:26:09,820 --> 00:26:11,710 not able to get into the restaurant. 394 00:26:11,710 --> 00:26:12,190 All right. 395 00:26:12,190 --> 00:26:14,620 So that's all I have for you in this lecture. 396 00:26:14,620 --> 00:26:18,910 And in the next lecture we're going to go ahead and start working on our door system. 397 00:26:18,910 --> 00:26:20,650 So I'll go ahead and see you there.